﻿using EMall.IdentityService.IdentityServers;
using EMall.Query;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace EMall.IdentityService.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class IdentityServerController : ControllerBase
    {
        private readonly IIdentityServerAppService _identityAppService;
        public IdentityServerController(IIdentityServerAppService identityAppService)
        {
            _identityAppService = identityAppService;
        }
        #region Client
        [HttpPost]
        public async Task CreateClientAsync(CreateClientDto input)
        {
            await _identityAppService.CreateClientAsync(input);
        }
        [HttpPut]
        public async Task UpdateClientAsync(UpdateClientDto input)
        {
            await _identityAppService.UpdateClientAsync(input);
        }
        [HttpDelete]
        public async Task DeleteClientAsync(DeleteClientDto input)
        {
            await _identityAppService.DeleteClientAsync(input);
        }
        [HttpGet]
        public async Task<IdentityServer4.EntityFramework.Entities.Client> GetClientAsync(int id)
        {
            return await _identityAppService.GetClientAsync(id);
        }
        [HttpGet]
        public async Task<IPagedList<IdentityServer4.EntityFramework.Entities.Client>> GetClientPagedListAsync([FromQuery] GetClientListPagingAndSortingQueryDto input)
        {
            return await _identityAppService.GetClientPagedListAsync(input);
        }
        #endregion
        #region ApiResource
        [HttpPost]
        public async Task CreateApiResourceAsync(CreateApiResourceDto input)
        {
            await _identityAppService.CreateApiResourceAsync(input);
        }
        [HttpPut]
        public async Task UpdateApiResourceAsync(UpdateApiResourceDto input)
        {
            await _identityAppService.UpdateApiResourceAsync(input);
        }
        [HttpDelete]
        public async Task DeleteApiResourceAsync(DeleteApiResourceDto input)
        {
            await _identityAppService.DeleteApiResourceAsync(input);
        }
        [HttpGet]
        public async Task<IdentityServer4.EntityFramework.Entities.ApiResource> GetApiResourceAsync(int id)
        {
            return await _identityAppService.GetApiResourceAsync(id);
        }
        [HttpGet]
        public async Task<IPagedList<IdentityServer4.EntityFramework.Entities.ApiResource>> GetApiResourcePagedListAsync([FromQuery] GetApiResourceListPagingAndSortingQueryDto input)
        {
            return await _identityAppService.GetApiResourcePagedListAsync(input);
        }
        #endregion
        #region ApiScope
        [HttpPost]
        public async Task CreateApiScopeAsync(CreateApiScopeDto input)
        {
            await _identityAppService.CreateApiScopeAsync(input);
        }
        [HttpPut]
        public async Task UpdateApiScopeAsync(UpdateApiScopeDto input)
        {
            await _identityAppService.UpdateApiScopeAsync(input);
        }
        [HttpDelete]
        public async Task DeleteApiScopeAsync(DeleteApiScopeDto input)
        {
            await _identityAppService.DeleteApiScopeAsync(input);
        }
        [HttpGet]
        public async Task<IdentityServer4.EntityFramework.Entities.ApiScope> GetApiScopeAsync(int id)
        {
            return await _identityAppService.GetApiScopeAsync(id);
        }
        [HttpGet]
        public async Task<IPagedList<IdentityServer4.EntityFramework.Entities.ApiScope>> GetApiScopePagedListAsync([FromQuery] GetApiScopeListPagingAndSortingQueryDto input)
        {
            return await _identityAppService.GetApiScopePagedListAsync(input);
        }
        #endregion
        #region IdentityResource
        [HttpPost]
        public async Task CreateIdentityResourceAsync(CreateIdentityResourceDto input)
        {
            await _identityAppService.CreateIdentityResourceAsync(input);
        }
        [HttpPut]
        public async Task UpdateIdentityResourceAsync(UpdateIdentityResourceDto input)
        {
            await _identityAppService.UpdateIdentityResourceAsync(input);
        }
        [HttpDelete]
        public async Task DeleteIdentityResourceAsync(DeleteIdentityResourceDto input)
        {
            await _identityAppService.DeleteIdentityResourceAsync(input);
        }
        [HttpGet]
        public async Task<IdentityServer4.EntityFramework.Entities.IdentityResource> GetIdentityResourceAsync(int id)
        {
            return await _identityAppService.GetIdentityResourceAsync(id);
        }
        [HttpGet]
        public async Task<IPagedList<IdentityServer4.EntityFramework.Entities.IdentityResource>> GetIdentityResourcePagedListAsync([FromQuery] GetIdentityResourceListPagingAndSortingQueryDto input)
        {
            return await _identityAppService.GetIdentityResourcePagedListAsync(input);
        }
        #endregion
        [HttpGet]
        public async Task<IdentityServer4.Models.Resources> GetAllResourcesAsync()
        {
            return await _identityAppService.GetAllResourcesAsync();
        }
    }
}
